﻿using Aribaccio;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.CompilerServices.RuntimeHelpers;

namespace BDPAutodetect.Models
{
    /// <summary>
    /// 从机设备视图模型数据
    /// </summary>
    public partial class MSlave : ObservableModel
    {
        /// <summary>
        /// 标识/编号
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(NameDisplay))]
        protected string name;

        /// <summary>
        /// 别称（简称描述）
        /// </summary>
        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(NameDisplay))]
        protected string? nameNick;

        /// <summary>
        /// 名称显示
        /// </summary>
        public string NameDisplay => !string.IsNullOrWhiteSpace(this.NameNick) ? this.NameNick : this.Name;

        public MSlave()
        {
            this.Name = "None";
            this.NameNick = "未知";
        }

        public MSlave(int argID, string argName, string? argNameNick)
        {
            this.ID = argID;
            this.Name = argName;
            this.NameNick = argNameNick;
        }

        /// <summary>
        /// 深度克隆
        /// </summary>
        /// <returns></returns>
        public MSlave CloneDeep()
        {
            return new MSlave()
            {
                ID = this.ID,
                Name = this.Name,
                NameNick = this.NameNick
            };
        }

        /// <summary>
        /// 克隆数据表
        /// </summary>
        /// <returns></returns>
        public TBasicSlave CloneTData()
        {
            return new TBasicSlave()
            {
                ID = this.ID,
                Name = this.Name,
                NameNick = this.NameNick
            };
        }
    }
}
